
var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var option;

option = {
  title: {
    text: '一天用电量分布',
    subtext: '纯属虚构'
  },
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'cross'
    }
  },
  legend: {
    data: ['用电量', '用电量2']
  },
  toolbox: {
    show: true,
    feature: {
      saveAsImage: {}
    }
  },
  xAxis: {
    type: 'category',
    axisLabel: {
      rotate: 0,
      interval: 0
    },
    boundaryGap: false,
    data: ['00:00', '01:15', '02:30', '03:45', '05:00', '06:15', '07:30', '08:45', '10:00', '11:15', '12:30', '13:45', '15:00', '16:15', '17:30', '18:45', '20:00', '21:15', '22:30', '23:45']
  },
  yAxis: {
    type: 'value',
    splitArea: {
      show: false  //y网格区域颜色
    },
    splitLine: {
      show: true,     //y网格线
      lineStyle: {
        color: '#a5854b'
      }
    },
    axisLine: {
      show: true,
      lineStyle: {
        color: '#333333'  //Y轴颜色
      }
    },
    nameTextStyle: {
      color: '#f44336'
    },
    axisLabel: {
      formatter: '{value} W'
    },
    axisPointer: {
      snap: true
    }
  },
  visualMap: [
    {
      show: false,
      dimension: 0,
      seriesIndex: 0,//设置位置
      pieces: [{
        lte: 6,
        color: 'green'
      }, {
        gt: 6,
        lte: 8,
        color: 'red'
      }, {
        gt: 8,
        lte: 14,
        color: 'green'
      }, {
        gt: 14,
        lte: 17,
        color: 'red'
      }, {
        gt: 17,
        color: 'green'
      }]
    }, {
      show: false,
      dimension: 0,
      seriesIndex: 1,
      pieces: [{
        lte: 5,
        color: 'green'
      }, {
        gt: 5,
        lte: 8,
        color: 'red'
      }, {
        gt: 8,
        lte: 14,
        color: 'green'
      }, {
        gt: 14,
        lte: 17,
        color: 'red'
      }, {
        gt: 17,
        color: 'green'
      }]
    }
  ],
  series: [
    {
      name: '用电量',
      seriesIndex: 0,
      type: 'line',
      smooth: true,
      data: [300, 280, 250, 260, 270, 300, 550, 500, 400, 390, 380, 390, 400, 500, 600, 750, 800, 700, 600, 400],
      markArea: {
        silent: false,
        //修改折线图的样式
        itemStyle: {
          color: 'rgba(255, 173, 177, 0.4)',

        },
        data: [[{
          name: '早高峰',
          xAxis: '07:30'
        }, {
          xAxis: '10:00'
        }], [{
          name: '晚高峰',
          xAxis: '17:30'
        }, {
          xAxis: '21:15'
        }]]
      }
    },
    {
      name: '用电量2',
      type: 'line',
      seriesIndex: 1,
      lineStyle: { color: '#03a9f4' },
      smooth: true,
      data: [400, 580, 450, 460, 470, 600, 750, 600, 700, 590, 580, 390, 200, 300, 200, 250, 300, 200, 400, 300],
      markArea: {
        silent: false,
        //修改折线图的样式
        itemStyle: {
          color: 'rgba(255, 173, 177, 0.4)'
        },
        data: [[{
          name: '早高峰',
          xAxis: '07:30'
        }, {
          xAxis: '10:00'
        }], [{
          name: '晚高峰',
          xAxis: '17:30'
        }, {
          xAxis: '21:15'
        }]]
      }
    }
  ]
};



if (option && typeof option === "object") {
  myChart.setOption(option, true);
}
